/*
 * CollisionManager.cpp
 *
 *  Created on: 22 mar 2010
 *      Author: hule
 */

#include "CollisionManager.h"
#include "SDL/SDL.h"
#include <iostream>

using namespace std;

CollisionManager::CollisionManager() {


}

CollisionManager::~CollisionManager() {

}

bool CollisionManager::circleCollision(int x1, int y1, int r1, int x2, int y2, int r2) {
	int dx = x2-x1;
	int dy = y2-y1;

	if ((dx*dx + dy*dy) <= (r1+r2)*(r1+r2) ) {
		return true;
	}
	return false;
}

bool CollisionManager::pixelCollision(SDL_Surface* s, int x, int y) {
	int newx = x + s->w/2.0;
	int newy = y + s->h/2.0;

	if (newx > 0 && newx < s->w && newy > 0 && newy < s->h) {
		int bpp = s->format->BytesPerPixel;

		// (s->h-newy) inverts y axis to get correct pixel reading from the surface
		Uint8 *p = (Uint8 *)s->pixels + (s->h-newy) * s->pitch + newx * bpp;

		//cout << (int)*p << endl;
		if ((int)*p!=0){
			return true;
		}else{

			return false;
		}

	}
	return false;
}
